/**
 * Created by Administrator on 15-10-9.
 */
function pi(){
    return  3.1415926535898;
}
pow=Math.pow;
sin=Math.sin;
cos=Math.cos;
asin=Math.asin;
min=Math.min;
sqrt=Math.sqrt;
window.onload=function() {
//导游
    var id = getUserId();
    var url = getUrl();
    var loc = getLoc();
    $.jsonp({
        url: 'http://'+url+'/api/collect/collect_guide_list',
        data: {guideId:id,userId:id},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
           //console.log(data)
            $.each(data.arrays,function(index,ele){
                var sex="female";
                if(ele.sex==1)
                    sex="male";
                earthRadius = 6371;
                var lat0 = (loc.lat * pi()) / 180;
                var lng0 = (loc.lng * pi()) / 180;
                var lat1 = (ele.dimensions * pi()) / 180;
                var lng1 = (ele.longitude * pi()) / 180;
                calcLongitude = lng1 - lng0;
                calcLatitude = lat1 - lat0;
                stepOne = pow(sin(calcLatitude / 2), 2) + cos(lat0) * cos(lat1) * pow(sin(calcLongitude / 2), 2);
                stepTwo = 2 * asin(min(1, sqrt(stepOne)));
                calculatedDistance = earthRadius * stepTwo;
                ele.distance=calculatedDistance.toFixed(1);
                var jumpurl="jumptoLogin("+"'daoyou_detail.html?guideId="+ele.guideId+"&distance="+ele.distance+"','daoyou_detail.html?guideId="+ele.guideId+"&distance="+ele.distance+"')";
                var html='<div onclick="'+jumpurl+'">' +
                    '<li class="ui-border-top">' +
                    '<div class="order-list-pic">' +
                    '<img src="'+ele.photos[0]+'" width="70" height="70" alt="">' +
                    '</div>' +
                    '<div class="order-list-intro">' +
                    '<div class="order-list-intro-text"' +
                    '<p>'+ele.guideName+'<span class="sex sex-'+sex+'"><i class="icons-sex-'+sex+'"></i>'+ele.age+'</span><span class="love-value"><i class="icons-love"></i>'+ele.popularity+'人气值</span></p>' +
                    '<p class="color666 fz14"><button class="ui-btn-s ui-btn-transparent-blue mr10">实名</button><button class="ui-btn-s ui-btn-transparent-blue mr10">导游证</button></p>' +
                    '<p class="ui-txt-muted"><i class="icons-lbs"></i>距离'+ele.distance+'KM</p>'+
                    '</div>' +
                    '<div class="order-list-price-list">' +
                    '<span class="ui-txt-red">'+ele.price+'元/天</span>'+
                    '</div>' +
                    '</div>' +
                    '</li>' +
                    '</a>';
                $(".order-list ").append(html)
            })
        },

        error: function (xOptions, textStatus) {
        }
    });
//    美食
    $.jsonp({
        url: 'http://'+url+'/api/collect/collect_shops_list',
        data: {shopsId:id,userId:id},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            $.each(data.arrays,function(index,ele){
                earthRadius = 6371;
                var lat0 = (loc.lat * pi()) / 180;
                var lng0 = (loc.lng * pi()) / 180;
                var lat1 = (ele.shopDimensions * pi()) / 180;
                var lng1 = (ele.shopLongitude * pi()) / 180;
                calcLongitude = lng1 - lng0;
                calcLatitude = lat1 - lat0;
                stepOne = pow(sin(calcLatitude / 2), 2) + cos(lat0) * cos(lat1) * pow(sin(calcLongitude / 2), 2);
                stepTwo = 2 * asin(min(1, sqrt(stepOne)));
                calculatedDistance = earthRadius * stepTwo;
                ele.distance=calculatedDistance.toFixed(1);
                var jumpurl = "jumptoLogin("+"'meishi_shangjiadetail.html?shopId="+ele.shopsId+"&distance="+ele.distance+"','meishi_shangjiadetail.html?shopId="+ele.shopsId+"&distance="+ele.distance+"')";
                var html= '<div onclick="'+jumpurl+'">' +
                    '<li class="ui-border-top">' +
                    '<div class="order-list-pic">' +
                    '<img src="'+ele.photos[0]+'" width="70" height="70" alt="">' +
                    '<h3>特色美食</h3>' +
                    '</div>' +
                    '<div class="order-list-intro">' +
                    '<div class="order-list-intro-text">' +
                    '<p>'+ele.shopName+'</p>' +
                    '<p class="ui-txt-highlight"><span class="ui-star ui-star-'+ele.star+'"></span>'+ele.star+'分</p>' +
                    '<p class="ui-txt-muted">'+ele.course+'</p>' +
                    '</div>' +
                    '<div class="order-list-detail-list">' +
                    '<p><span class="ui-txt-highlight">人均¥'+ele.avgPrice+'</span></p>' +
                    '<p class="ui-txt-muted"><i class="icons-lbs"></i>距离'+ele.distance+'KM</p>' +
                    '</div>' +
                    '</div>' +
                    '</li>';
                $(".order-list ").append(html)
            })
        },

        error: function (xOptions, textStatus,b) {

        }
    });

    //摄影
    $.jsonp({
        url: 'http://'+url+'/api/collect/collect_camera_list',
        data: {shopsId:id,userId:id},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            $.each(data.arrays,function(index,ele){
                earthRadius = 6371;
                var lat0 = (loc.lat * pi()) / 180;
                var lng0 = (loc.lng * pi()) / 180;
                var lng1 = (ele.cameraDimensions * pi()) / 180;
                var lat1 = (ele.cameraLongitude * pi()) / 180;
                calcLongitude = lng1 - lng0;
                calcLatitude = lat1 - lat0;
                stepOne = pow(sin(calcLatitude / 2), 2) + cos(lat0) * cos(lat1) * pow(sin(calcLongitude / 2), 2);
                stepTwo = 2 * asin(min(1, sqrt(stepOne)));
                calculatedDistance = earthRadius * stepTwo;
                ele.distance=calculatedDistance.toFixed(1);
                var jumpurl = "jumptoLogin("+"'sheying_detail.html?cameraId="+ele.cameraId+"&distance="+ele.distance+"','sheying_detail.html?cameraId="+ele.cameraId+"&distance="+ele.distance+"')";
                var html='<div onclick="'+jumpurl+'">' +
                    '<li class="ui-border-top">' +
                    '<div class="order-list-pic">' +
                    '<img src="img/order_list_pic.jpg" width="70" height="70" alt="">' +
                    '<h3>摄影位置</h3>' +
                    '</div>' +
                    '<div class="order-list-intro">' +
                    '<div class="order-list-intro-text">' +
                    '<p>'+ele.spotsName+'</p>' +
                    '<p class="ui-txt-highlight"><span class="ui-star ui-star-'+ele.star+'"></span>'+ele.star+'分</p>' +
                    '<p class="ui-txt-muted"><i class="icons-lbs"></i>距离'+ele.distance+'KM</p>' +
                    '</div>' +
                    '</div>' +
                    '</li>' +
                    '</a>';
                $(".order-list ").append(html)
            })
        },
        error: function (xOptions, textStatus) {
        }
    });



    //租车
    $.jsonp({
        url: 'http://'+url+'/api/collect/collect_rcar_list',
        data: {rcarId:id,userId:id},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
//console.log(data.arrays.rcarName)
            $.each(data.arrays, function (index, ele) {
                var sex="female";
                if(ele.sex==1){
                sex="male";}
                earthRadius = 6371;
                var lat0 = (loc.lat * pi()) / 180;
                var lng0 = (loc.lng * pi()) / 180;
                var lat1 = (ele.rcarDimensions * pi()) / 180;
                var lng1 = (ele.rcarLongitude * pi()) / 180;
                calcLongitude = lng1 - lng0;
                calcLatitude = lat1 - lat0;
                stepOne = pow(sin(calcLatitude / 2), 2) + cos(lat0) * cos(lat1) * pow(sin(calcLongitude / 2), 2);
                stepTwo = 2 * asin(min(1, sqrt(stepOne)));
                calculatedDistance = earthRadius * stepTwo;
                ele.distance = calculatedDistance.toFixed(1);
                var jumpurl = "jumptoLogin("+"'car_detail.html?rcarId="+ele.rcarId+"&distance="+ele.distance+"','car_detail.html?rcarId="+ele.rcarId+"&distance="+ele.distance+"')";
                var html =  '<div onclick="'+jumpurl+'">' +
                    '<li class="ui-border-top">' +
                    '<div class="order-list-pic">' +
                    '<img src="'+ele.photos[0]+'" width="70" height="70" alt="">' +
                    '<h3>租车用车</h3>' +
                    '</div>' +
                    '<div class="order-list-intro">' +
                    '<div class="order-list-intro-text">' +
                    '<p>' + ele.rcarName + '<span class="sex sex-'+sex+'"><i class="icons-sex-'+sex+'"></i>' + ele.age + '</span></p>' +
                    '<p class="ui-txt-highlight"><span class="ui-star ui-star-' + ele.star + ' "></span>' + ele.star + '分</p>' +
                    '<p class="ui-txt-muted"><i class="icons-lbs"></i>距离' + ele.distance + 'KM</p>' +
                    '</div>' +
                    '<div class="order-list-detail-list">' +
                    '<p><span class="ui-txt-highlight">¥' + ele.price + '/天</span></p>' +
                    '</div>' +
                    '</div>' +
                    '</li>' +
                    '</a>';
                $(".order-list ").append(html)
            })
        },

        error: function (xOptions, textStatus) {
        }
    });
    //手工艺人
    var id=getUserId();
    $.jsonp({
        url: 'http://'+url+'/api/collect/collect_shops_list',
        data: {shopsId:id,userId:id},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            $.each(data.arrays,function(index,ele){
                earthRadius = 6371;
                var lat0 = (loc.lat * pi()) / 180;
                var lng0 = (loc.lng * pi()) / 180;
                var lat1 = (ele.shopDimensions * pi()) / 180;
                var lng1 = (ele.shopLongitude * pi()) / 180;
                calcLongitude = lng1 - lng0;
                calcLatitude = lat1 - lat0;
                stepOne = pow(sin(calcLatitude / 2), 2) + cos(lat0) * cos(lat1) * pow(sin(calcLongitude / 2), 2);
                stepTwo = 2 * asin(min(1, sqrt(stepOne)));
                calculatedDistance = earthRadius * stepTwo;
                ele.distance = calculatedDistance.toFixed(1);
                var jumpurl = "jumptoLogin("+"'yiren_detail.html?shopId="+ele.shopsId+"&distance="+ele.distance+"','yiren_detail.html?shopId="+ele.shopsId+"&distance="+ele.distance+"')";
                var html='<div onclick="'+jumpurl+'">' +
                    '<li class="ui-border-top">' +
                    '<div class="order-list-pic">' +
                    '<img src="'+ele.photos[0]+'" width="70" height="70" alt="">' +
                    '<h3>手工艺人</h3>' +
                    '</div>' +
                    '<div class="order-list-intro">' +
                    '<div class="order-list-intro-text">' +
                    '<p>'+ele.shopName+'</p>' +
                    '<p class="ui-txt-highlight"><span class="ui-star ui-star-'+ele.star+'"></span>'+ele.star+'分</p>' +
                    '<p class="ui-txt-muted"><i class="icons-lbs"></i>距离'+ele.distance+'KM</p>' +
                    '</div>' +
                    '</div>' +
                    '</li>' +
                    '</a>';
                $(".order-list ").append(html)
            })
        },

        error: function (xOptions, textStatus) {
        }
    });

 }